//
//  ScenicPlayVC.m
//  ImGuider/Users/wangpengyu/Desktop/ImGuider2/ImGuider/Vendor/SDCycleScrollView
//
//  Created by llt on 2017/4/19.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "ScenicNodePlayVC.h"
#import "ScenicPlayCCell.h"
#import "MyPlayProgressView.h"
#import "PlayBar.h"
#import "SDCycleScrollView.h"
#import "StarRateView.h"
#import "TagView.h"
#import "CBAutoScrollLabel.h"
//#import "NumberSearchVC.h"
//#import "JMHoledView.h"
//#import "RecordListDAO.h"
#import "SDPhotoBrowser.h"

#import "IGAvPlayerManager.h"

#import "UserSubmitQustionVC.h"
#import "UserCommentsVC.h"
#import <AVFoundation/AVFoundation.h>
#import "MyCamera.h"

#import "SearchScenicPointCCell.h"
//#import "NoticeGuide.h"
#import <IQTextView.h>
#import "UIImage+BlurView.h"
#import "PlayerItem.h"
#import "NoticeGuide.h"
//#import "DataCollectionManager.h"

#define TextViewHeight (ISiPhone5 || ISiPhone4) ?  50 : 70



@interface ScenicNodePlayVC () <UICollectionViewDelegate, UICollectionViewDataSource, UIViewControllerTransitioningDelegate,playBarDelegate,SDCycleScrollViewDelegate,SDPhotoBrowserDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *backBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *backBtnTopSpace;

@property (weak, nonatomic) IBOutlet UIButton *shareButton;

@property (weak, nonatomic) IBOutlet UIView *BgView;

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;



@property (weak, nonatomic) IBOutlet UILabel *resultTipLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *resultTipLabelHeight;

@property (weak, nonatomic) IBOutlet IQTextView *textView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textViewHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textViewTopSpace;


@property (weak, nonatomic) IBOutlet UIView *keyBoardView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *keyBoardHeight;


@property (weak, nonatomic) IBOutlet UIView *menuView;
@property (weak, nonatomic) IBOutlet UIButton *arrowBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewBottomSpace;

@property (nonatomic, strong) NSMutableArray * menuTagsArray;

@property (nonatomic, strong)SDCycleScrollView *cycleScrollView;

@property (nonatomic, strong)PlayBar * playBar;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong)NSMutableArray * resultArray;

@property (nonnull, strong) MyPlayProgressView * progressBar;

@property (nonatomic, strong)NSIndexPath * currenIndexPath;
@property (nonatomic) NSInteger currentIndex;
@property (nonatomic)BOOL isPlay;

@property (nonatomic)BOOL isInView;// 为了改点的太快 出去播放的bug

@property (nonatomic)BOOL isDownload;

@property (nonatomic) BOOL isSuspend;

@property (nonatomic, assign)BOOL isAll;// 是否是查看全部模式  yes  是  NO 不是；

@property (nonatomic, strong)UIImagePickerController * imagePickerVC;

@property (nonatomic, strong)UIView * maskView;
@property (nonatomic, strong)UIImageView *imageView;
@property (nonatomic, assign)BOOL isSearchOrAllPoint;

@property (weak, nonatomic) IBOutlet UIButton *searchDeleteBtn;


@end

@implementation ScenicNodePlayVC


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDownload) name:MCDownloadStartNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDownload) name:MCDownloadStopNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDownload) name:MCDownloadFinishNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccessCallback) name:kLoginSuccessNotif object:nil];
    
    // self.mapBtn.hidden = YES;
    
    //    [self.searchBtn setTitle:MYLocalizedString(@"SITEPLAY_SEARCH", nil) forState:UIControlStateNormal];
    UIImage * image = [UIImage imageNamed:@"close"];
    UIImage * image2 = [UIImage imageNamed:@"back"];
    [self.backBtn setImage:[image imageByTintColor:[UIColor whiteColor]] forState:UIControlStateSelected];
    [self.backBtn setImage:[image2 imageByTintColor:[UIColor whiteColor]] forState:UIControlStateNormal];
    if (ISiPhoneX) {
        self.backBtnTopSpace.constant = 40;
    }
    [self.shareButton setImage:[UIImage imageNamed:@"分享"] forState:UIControlStateNormal];
    self.isSearchOrAllPoint = YES;
    self.view.backgroundColor = kBGColor;
    self.collectionView.hidden = YES;
    [self setupCollectionView];
    [self createPlayBar];
    [self initKeyBoardView];
    
    if (self.lineModel) {
        [self loadDataSourceWithAlert:self.alert];
    }else {
        [self loadDataSource];
    }
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    NSString *lineid = self.lineid;
    
    if (lineid.length == 0) {
        lineid = self.lineModel.lineid;
    }
    
   // [[DataCollectionManager sharedManager] enterPlayerPageWithLineid:lineid];
    
}


- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    // [MobClick event:@"7_1_1"];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
    self.isInView = YES;
    [[PlayerItem playItemShareManager] hide];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    if (![[IGAvPlayerManager shareManeger].currentURL isEqualToString:self.currentScenicPoint.playpath] && self.currentScenicPoint) {
        [IGAvPlayerManager shareManeger].playType = PlayLine;
        [self.playBar playMusicWithIndex:self.currentIndex withIsPlay:NO];
    }else if([[IGAvPlayerManager shareManeger].currentURL isEqualToString:self.currentScenicPoint.playpath] && self.currentScenicPoint && self.isPlay){
        
        [[IGAvPlayerManager shareManeger] play];
    }
    if(self.isItemIn){
        [self maskViewDisappearIsAnimation:YES];
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.isInView = NO;
   // [self.navigationController setNavigationBarHidden:NO];
//    if (![IGAvPlayerManager shareManeger].isPlay) {
//        
//        [[IGAvPlayerManager shareManeger] stop];
//    }
//    
//    [PlayerItem playItemShareManager].point = self.currentScenicPoint;
//    [PlayerItem playItemShareManager].lineModel = self.lineModel;
//    
//    [[PlayerItem playItemShareManager] show];
    
}

- (IBAction)backBtnTapAction:(UIButton *)sender {
    if (sender.selected) {
        [self maskViewDisappearIsAnimation:YES];
    }else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (IBAction)shareButtonClicked:(UIButton *)sender {
    
    if (!sender.isSelected) {
        [self showShareSheet:sender];
    }
}

- (UIView *)maskView {
    if (!_maskView) {
        _maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 146)];
        [self.BgView insertSubview:_maskView belowSubview:self.menuView];
        _imageView = [[UIImageView alloc] init];
        [_maskView addSubview:_imageView];
        [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_maskView.mas_top);
            make.leading.equalTo(_maskView.mas_leading);
            make.trailing.equalTo(_maskView.mas_trailing);
            make.bottom.equalTo(_maskView.mas_bottom);
        }];
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(maskViewDisappearIsAnimation:)];
        [_maskView addGestureRecognizer:tap];
    }
    
    return _maskView;
}


-(void)maskViewAppear{
    @weakify(self)
    [self.imageView setImageWithURL:[NSURL URLWithString:self.currentScenicPoint.pictureArray.firstObject] placeholder:[UIImage imageNamed:@""] options:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
        
        @strongify(self)
        self.imageView.image = [image blurredImageWithRadius:15 iterations:5 tintColor:[UIColor blackColor]];
    }];
    if (!self.isSearchOrAllPoint || self.resultArray.count > 0) {
        self.collectionView.hidden = NO;
    }
    if (self.textView.text.length > 0) {
        self.searchDeleteBtn.hidden = NO;
    }
    self.backBtn.selected = YES;
    self.shareButton.hidden = YES;
    self.maskView.hidden = NO;
}

-(void)maskViewDisappearIsAnimation:(BOOL)animation{
    self.resultTipLabel.text = @"";
    self.keyBoardHeight.constant = 0.f;
    self.textViewHeight.constant = 0;
    self.textView.hidden = YES;
    self.maskView.hidden = YES;
    self.collectionView.hidden = YES;
    self.title = self.currentScenicPoint.spotname;
    self.backBtn.selected = NO;
    self.shareButton.hidden = NO;
    self.searchDeleteBtn.hidden = YES;
    if (animation) {
       
        [UIView animateWithDuration:0.3 animations:^{
            [self.view layoutIfNeeded];
        } completion:^(BOOL finished) {
            self.keyBoardView.hidden = YES;
        }];
    }else {
        self.keyBoardView.hidden = YES;
    }
    
}



- (void)initKeyBoardView {
    
    NSArray * arr = @[@"1",@"2",@"3",@"0",@"4",@"5",@"6",@"删除",@"7",@"8",@"9"];//,@"清空"
    
    CGFloat Hspace = 16;
    CGFloat Vspace = 11;
    CGFloat width = (kScreenWidth - 80)/4;
    CGFloat Height =((BoardHeight) - 44)/3;
    CGFloat Y = Vspace;
    for (NSInteger i = 0; i < arr.count; i++) {
        
        if (i == 4) {
            Y = Vspace * 2 + Height;
        }else if(i == 8){
            Y = Vspace * 3 + Height * 2;
        }
        NSInteger num = i%4;
        NSString * str = arr[i];
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(Hspace + num *(Hspace + width), Y, width, Height);
        
        btn.backgroundColor = [UIColor colorWithRed:220/255.0 green:223/255.0 blue:228/255.0 alpha:0.6];
       
        if ([str isEqualToString:@"删除"]) {
            [btn setImage:[UIImage imageNamed:@"deletekey"] forState:UIControlStateNormal];
            btn.frame = CGRectMake(Hspace + num *(Hspace + width), Y, width, 2 * Height + Vspace);
        }else {
            [btn setTitle:str forState:UIControlStateNormal];
            [btn setTitleColor:kTitleColor forState:UIControlStateNormal];
        }
        
        [btn addTarget:self action:@selector(keyAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.keyBoardView addSubview:btn];
        
        self.textViewHeight.constant = TextViewHeight;
        self.textView.inputView =  nil;
        self.searchDeleteBtn.hidden = YES;
    }
    
    self.maskView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.8];
    self.textView.editable = NO;
    self.textView.font = Font(40);
    if (ISiPhone5 || ISiPhone4) {
        self.textView.font = Font(32);
    }
    
    self.shareButton.hidden = YES;
    self.keyBoardHeight.constant = BoardHeight;
    self.textView.textColor = [UIColor whiteColor];
    self.textView.textAlignment = NSTextAlignmentCenter;
    self.textViewTopSpace.constant = kNavigationBarHeight;
    self.title = MYLocalizedString(@"SEARCH_NODE_TITLE", nil);
    self.keyBoardView.backgroundColor = [UIColor whiteColor];//kThemeDarkColor;
}

- (void)setTitle:(NSString *)title {
    
    self.titleLabel.text = title;
}

- (IBAction)searchDeleteAction:(UIButton *)sender {
    
    [self.resultArray removeAllObjects];
    self.resultArray = nil;
    self.textView.text = @"";
    self.resultTipLabel.text = @"";
    [self.collectionView reloadData];
    self.collectionView.hidden = YES;
    self.title = MYLocalizedString(@"SEARCH_NODE_TITLE", nil);
    self.searchDeleteBtn.hidden = YES;
}

- (void)keyAction:(UIButton *)sender {
    
    if (sender.currentTitle.length == 0 ) {
        if (self.textView.text.length >= 1) {
            self.textView.text = [self.textView.text substringToIndex:self.textView.text.length - 1];
        }
        if (self.textView.text.length == 0) {
            [self.resultArray removeAllObjects];
            self.resultArray = nil;
            self.resultTipLabel.text = @"";
            self.searchDeleteBtn.hidden = YES;
            [self.collectionView reloadData];
            self.collectionView.hidden = YES;
        }
        
        self.title = MYLocalizedString(@"SEARCH_NODE_TITLE", nil);
    }else{
        self.searchDeleteBtn.hidden = NO;
        NSMutableString * str = [NSMutableString stringWithString:self.textView.text];
        if (str.length <5) {
            [str appendString:sender.currentTitle];
            self.textView.text = str;
        }
    }
    if (self.textView.text.length > 2) {
        [self BeginWith:self.textView.text];
    }
}

- (void)searchNodeNumberWith:(NSString *)searchText{
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nodenumber like %@", searchText];
    self.resultArray = [NSMutableArray arrayWithArray:[self.lineModel.records filteredArrayUsingPredicate:predicate]] ;
    if (self.resultArray.count > 0) {
        [self setSearchResultWith:1];
    }else {
        self.resultArray = [NSMutableArray arrayWithArray:[self getMayBeRsultWith:searchText]];
        if (self.resultArray.count > 0) {
            [self setSearchResultWith:2];
        }else {
            [self setSearchResultWith:0];
        }
    }
}

- (void)BeginWith:(NSString *)searchText {
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nodenumber beginswith %@", searchText];
    self.resultArray = [NSMutableArray arrayWithArray:[self.lineModel.records filteredArrayUsingPredicate:predicate]];
    self.resultTipLabel.text = MYLocalizedString(@"SEARCH_NODE_RESULT_TIP", nil);
    if (self.resultArray.count > 0) {
        
        [self setSearchResultWith:1];
    }else {
        self.resultArray = [NSMutableArray arrayWithArray:[self getMayBeRsultWith:searchText]];
        if (self.resultArray.count > 0) {
            [self setSearchResultWith:2];
        }else {
            [self setSearchResultWith:0];
        }
    }
}

- (void)setSearchResultWith:(NSInteger)resultState{
    
    if (self.resultArray.count > 1 ) {
        
        [self.resultArray sortUsingComparator:^NSComparisonResult(ScenicPoint *  _Nonnull obj1, ScenicPoint *   _Nonnull obj2) {
            int result = self.textView.text.intValue;
            return  abs(result - obj1.nodenumber.intValue) > abs(result - obj2.nodenumber.intValue);
        }];
    }
    
    switch (resultState) {
        case 0://下面两中都没搜到结果
        {
            self.title = [NSString stringWithFormat:MYLocalizedString(@"SEARCH_NODE_RESULT", nil),self.textView.text];
            self.collectionView.hidden = YES;
            self.resultTipLabel.text = @"";
        }
            break;
        case 1://搜到有前缀 的结果   如  123##
        {
            self.resultTipLabelHeight.constant = 30;
            self.collectionView.hidden = NO;
            [self.collectionView reloadData];
        }
            break;
        case 2:// 按前缀没有搜到结果   然后 用   ？234 || 1？34 || 12？4 || 123？ 搜到结果
        {
            self.title = [NSString stringWithFormat:MYLocalizedString(@"SEARCH_NODE_RESULT", nil),self.textView.text];
            self.resultTipLabelHeight.constant = 30;
            self.collectionView.hidden = NO;
            [self.collectionView reloadData];
        }
            break;
        default:
            break;
    }
    
}

- (NSArray *)getMayBeRsultWith:(NSString *)searchText {
    
    NSPredicate *predicate =  [NSPredicate predicateWithFormat:@"nodenumber like %@",@"00"];
    
    NSMutableString * str1 = [NSMutableString stringWithFormat:@"%@",searchText];
    [str1 replaceCharactersInRange:NSMakeRange(0, 1) withString:@"?"];
    
    NSMutableString * str2 = [NSMutableString stringWithFormat:@"%@",searchText];
    [str2 replaceCharactersInRange:NSMakeRange(1, 1) withString:@"?"];
    
    NSMutableString * str3 = [NSMutableString stringWithFormat:@"%@",searchText];
    [str3 replaceCharactersInRange:NSMakeRange(2, 1) withString:@"?"];
    
    if (searchText.length == 3) {
        predicate = [NSPredicate predicateWithFormat:@"nodenumber like %@ || nodenumber like %@ || nodenumber like %@", str1,str2,str3];
        
    }else if(searchText.length == 4){
        
        NSMutableString * str4 = [NSMutableString stringWithFormat:@"%@",searchText];
        [str4 replaceCharactersInRange:NSMakeRange(3, 1) withString:@"?"];
        
        predicate = [NSPredicate predicateWithFormat:@"nodenumber like %@ || nodenumber like %@ || nodenumber like %@ || nodenumber like %@", str1,str2,str3,str4];
        
    }else if(searchText.length == 5){
        
        NSMutableString * str4 = [NSMutableString stringWithFormat:@"%@",searchText];
        [str4 replaceCharactersInRange:NSMakeRange(3, 1) withString:@"?"];
        
        NSMutableString * str5 = [NSMutableString stringWithFormat:@"%@",searchText];
        [str4 replaceCharactersInRange:NSMakeRange(4, 1) withString:@"?"];
        
        predicate = [NSPredicate predicateWithFormat:@"nodenumber like %@ || nodenumber like %@ || nodenumber like %@ || nodenumber like %@  || nodenumber like %@", str1,str2,str3,str4,str5];
    }
    
    return [self.lineModel.records filteredArrayUsingPredicate:predicate];
}
- (void)showSearchOrAllPointWith:(BOOL) isShow {
    
    self.isSearchOrAllPoint = isShow;
    
    if (isShow) {
        //搜索界面
        self.isAll = NO;
        self.keyBoardHeight.constant = BoardHeight;
        // self.collectionView.hidden = YES;
        self.keyBoardView.hidden = NO;
        self.textViewHeight.constant = TextViewHeight;
        if(self.resultArray.count > 0){
            self.resultTipLabel.text = MYLocalizedString(@"SEARCH_NODE_RESULT_TIP", nil);
            self.resultTipLabelHeight.constant = 30;
            self.searchDeleteBtn.hidden = NO;
        }else {
            self.resultTipLabel.text = @"";
            self.collectionView.hidden = YES;
            self.searchDeleteBtn.hidden = YES;
        }
        
        self.textView.hidden = NO;
        self.title = MYLocalizedString(@"SEARCH_NODE_TITLE", nil);
    }else {
        self.isAll = YES;
        //全部讲解点界面
        self.keyBoardHeight.constant = 0.f;
        self.collectionView.hidden = NO;
        self.title = MYLocalizedString(@"GUIDE_PLAYER_ALL", nil);
        self.textViewHeight.constant = 0;
        self.textView.hidden = YES;
        self.resultTipLabel.text = @"";
        self.resultTipLabelHeight.constant = 0;
        self.searchDeleteBtn.hidden = YES;
    }
    
    [self noviceGuide];
    
    [UIView animateWithDuration:0.3 animations:^{
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        
        if (isShow == YES) {
            
        }else{
            self.keyBoardView.hidden = YES;
        }
        [self.collectionView reloadData];
        
        
    }];
    
}

- (UIImagePickerController *)imagePickerVC {
    
    if (_imagePickerVC == nil) {
        _imagePickerVC = [[UIImagePickerController alloc] init];
        _imagePickerVC.delegate = self;
        // set appearance / 改变相册选择页的导航栏外观
        _imagePickerVC.navigationBar.barTintColor = kThemeColor;
        _imagePickerVC.navigationBar.tintColor = [UIColor whiteColor];
        //        _imagePickerVC.allowsEditing = NO;
    }
    return _imagePickerVC;
}

- (void)setMenuTagsArray:(NSMutableArray *)menuTagsArray {
    
    _menuTagsArray = [NSMutableArray arrayWithArray:menuTagsArray];
    
    if (!(self.lineModel.mapPicArray.count > 0)) {
        [_menuTagsArray removeObject:@(MenuTypeMap)];
    }
    
    if (!self.lineModel.cansearch) {
        [_menuTagsArray removeObject:@(MenuTypeNode)];
    }
}
- (void)setupMenuView {
    
    CGFloat width = kScreenWidth / self.menuTagsArray.count;
    
    for (int i = 0; i< self.menuTagsArray.count; i ++) {
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(i * width, 0, width, 48);
        [self.menuView addSubview:btn];
        
        NSNumber * type = self.menuTagsArray[i];
        
        switch (type.integerValue) {
            case MenuTypeQuestion:
            {
                [btn setImage:[UIImage imageNamed:@"question-grey"] forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(goQuestion) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case MenuTypeComment:
            {
                [btn setImage:[UIImage imageNamed:@"comment-grey"] forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(goComment) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case MenuTypeMap:
            {
                [btn setImage:[UIImage imageNamed:@"map-grey"] forState:UIControlStateNormal];
                [btn setImage:[UIImage imageNamed:@"pic-grey"] forState:UIControlStateSelected];
                self.changeMapBtn = btn;
                [btn addTarget:self action:@selector(changeMapMode:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case MenuTypeCamera:
            {
                [btn setImage:[UIImage imageNamed:@"camera-grey"] forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(goCamera) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case MenuTypeNode:
            {
                [btn setImage:[UIImage imageNamed:@"列表"] forState:UIControlStateNormal];
                [btn setImage:[UIImage imageNamed:@"键盘"] forState:UIControlStateSelected];
                [btn addTarget:self action:@selector(changeTab:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            default:
                break;
        }
    }
    self.menuView.backgroundColor =[UIColor whiteColor];// [kThemeDarkColor colorWithAlphaComponent: 0.95];
    [self noviceGuide];
}

- (void)noviceGuide {
    
    
    if (![self.menuTagsArray containsObject:@(MenuTypeNode)]) {
        
        return;
    }
    
    
    NSMutableArray *tagArray = [NSMutableArray arrayWithArray:self.menuTagsArray];
    
    [tagArray removeObject:@(MenuTypeNode)];
    
    CGFloat height = CGRectGetMinY(self.menuView.frame);
    
    if (self.isAll) {
        
        [tagArray addObject:@(MenuTypeKeyboard)];
        
    } else {
        
        [tagArray addObject:@(MenuTypeList)];
    }
    
    [NoticeGuide showPlayerWithMenu:tagArray vc:self];
}

- (IBAction)upOrDown:(UIButton *)sender {
    
    //    NSString * name;
    //    BOOL flag = false;
    //
    //    if (sender.selected) {
    //        name = @"展开";
    //        self.keyBoardHeight.constant = 140.f;
    //        self.collectionView.hidden = NO;
    //        sender.selected = NO;
    //
    //    }else {
    //
    //        name = @"收起";
    //        self.keyBoardHeight.constant = 0.f;
    //        flag = YES;
    //    }
    //
    //    [UIView animateWithDuration:0.3 animations:^{
    //        [self.view layoutIfNeeded];
    //    } completion:^(BOOL finished) {
    //
    //        if (flag == YES) {
    //            self.collectionView.hidden = flag;
    //            sender.selected = flag;
    //        }
    //        [sender setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
    //    }];
    
}



- (void)changeState:(NSNotification *)notif {
    
    if (self.isSuspend) {
        return;
    }
    
    
    //    dispatch_async(dispatch_get_main_queue(), ^ {
    //
    //        NSString *lineID = notif.userInfo[kDownloadNotifLineID];
    //
    //        if (![lineID isEqualToString:self.lineModel.unionid]) {
    //            return;
    //        }
    //
    //        CGFloat progress;
    //        //DownloadState state = [[DownloadManager sharedManager] downloadSateForModel:self.lineModel progress:&progress];
    //
    //        self.lineModel.progress = progress;
    //       // self.lineModel.state = state;
    //
    //        self.playBar.downloadState = state;
    //        self.playBar.downloadProgress = progress;
    //        [self.collectionView reloadData];
    //    });
}

- (IBAction)searchBtnClicked:(UIButton *)sender {
    
    //    NumberSearchVC * searchVC = [[NumberSearchVC alloc] init];
    //
    //    searchVC.ScenicPointsArray = self.dataSource;
    //    searchVC.delegate = self;
    //    self.isStraightPlay = YES;
    //    RTRootNavigationController * nav = [[RTRootNavigationController alloc] initWithRootViewController:searchVC];
    //
    //    [self presentViewController:nav animated:YES completion:nil];
}


//- (IBAction)changeMap:(UIButton *)sender {
//
//    if (!sender.selected) {
//        self.cycleScrollView.imageURLStringsGroup = self.lineModel.mapPicArray;
//        self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
//        self.cycleScrollView.autoScroll = NO;
//        sender.selected = YES;
//    }else {
//        ScenicPoint * scenicPoint = self.dataSource[self.currentIndex];
//         self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
//        self.cycleScrollView.imageURLStringsGroup = scenicPoint.pictureArray;
//        if (scenicPoint.pictureArray.count > 1) {
//            self.cycleScrollView.autoScroll = YES;
//        }else {
//            self.cycleScrollView.autoScroll = NO;
//        }
//
//        sender.selected = NO;
//    }
//}

- (void)goQuestion {
    
    UserSubmitQustionVC *questionVC = [[UserSubmitQustionVC alloc] init];
    
    questionVC.lineModel = self.lineModel;
    
    
    [self.navigationController pushViewController:questionVC animated:YES];
}

- (void)setIsDownload:(BOOL)isDownload {
    
    
    if (_isDownload == isDownload) {
        return;
    }
    
    _isDownload = isDownload;
    
    [self.collectionView reloadData];
    
}

-(void)goComment {
    
    UserCommentsVC * commentVC = [[UserCommentsVC alloc] init];
    
    if (self.lineModel.hasscore.integerValue >0) {
        
        commentVC.isCanComment = NO;
    }else {
        
        commentVC.isCanComment = YES;
    }
    
    
    
    commentVC.lineID = self.lineModel.lineid;
    [self.navigationController pushViewController:commentVC animated:YES];
}

- (void)changeMapMode:(UIButton *)sender {
    
    [self maskViewDisappearIsAnimation:YES];
    
    if (!sender.selected) {
        self.cycleScrollView.imageURLStringsGroup = self.lineModel.mapPicArray;
        self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
        self.cycleScrollView.autoScroll = NO;
        sender.selected = YES;
    }else {
        ScenicPoint * scenicPoint = self.dataSource[self.currentIndex];
        self.cycleScrollView.imageURLStringsGroup = scenicPoint.pictureArray;
        if (scenicPoint.pictureArray.count > 1) {
            self.cycleScrollView.autoScroll = YES;
        }else {
            self.cycleScrollView.autoScroll = NO;
        }
        sender.selected = NO;
        self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    }
}

- (void)goCamera {
    if ([self canUserCamera]) {
        
        if ([IGAvPlayerManager shareManeger].isPlay) {
            self.isPlay = YES;
        }
        MyCamera * cameraVC = [[MyCamera alloc] init];
        self.isHideItem = YES;
        [self presentViewController:cameraVC animated:YES completion:nil];
    }else{
        return;
    }
    
}

- (BOOL)canUserCamera {
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusDenied) {
        
        [IGAlertView alertWithTitle:nil message:MYLocalizedString(@"PUBLIC_CAMERA_ALERT_CONTENT", nil) cancelButtonTitle:MYLocalizedString(@"PUBLIC_CANCEL", nil) commitBtn:MYLocalizedString(@"PUBLIC_NOGPS_ALERT_COMMIT", nil) commit:^{
            NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
            
            if([[UIApplication sharedApplication] canOpenURL:url]) {
                
                [[UIApplication sharedApplication] openURL:url];
                
            }
        } cancel:nil];
        
        return NO;
    }
    else{
        return YES;
    }
}

- (void)changeTab:(UIButton *)sender {
    
    [self maskViewAppear];
    if (sender.selected) {
        [self showSearchOrAllPointWith:YES];
        sender.selected = NO;
    }else {
        [self showSearchOrAllPointWith:NO];
        sender.selected = YES;
    }
}


- (IBAction)payBtnClicked:(UIButton *)sender {
    
    //    [MobClick event:@"7_1_2"];
    //
    //    if (![IGUtil hasLoginOrPresentLogin]) {
    //        return;
    //    }
    //
    //    LinePaymentVC * paymentVC = [[LinePaymentVC alloc] init];
    //    paymentVC.lineModel = self.lineModel;
    //    paymentVC.delegate = self;
    //    RTRootNavigationController * nav = [[RTRootNavigationController alloc] initWithRootViewController:paymentVC];
    //
    //    [self presentViewController:nav animated:YES completion:nil];
}

- (void)selectSenicPoint:(ScenicPoint *)point {
    
    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[self.dataSource  indexOfObject:point] inSection:0];
    
    //   @weakify(self);
    
    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //        @strongify(self);
    //        if (self.lineModel.bought && self.isInView) {
    //
    //            [self selectCellWithIndex:indexPath.row Immediately:YES];
    //        }else {
    //
    //            self.cycleScrollView.imageURLStringsGroup = point.pictureArray;
    //            [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    //        }
    //    });
    
    if (self.lineModel.bought && self.isInView) {
        
        [self selectCellWithIndex:indexPath.row Immediately:YES];
    }
}
- (void)loadDataSourceWithAlert:(BOOL)alert {
    
    //    if (self.pageType == 1) {
    //
    //        self.isDownload = YES;
    //        [self setupData];
    //
    //        @weakify(self);
    //        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    //
    //            @strongify(self);
    //            [self reloadDownload];
    //        });
    //
    //        return;
    //    }
    
    [self setupData];
    
    NSString *name = [self.lineModel.playpath componentsSeparatedByString:@"/"].lastObject;
    
    if (name.length > 0) {
        
        NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
        
        if (path.length > 0) {
            
            self.isDownload = YES;
            self.playBar.downloadState = MCDownloadStateCompleted;
            self.playBar.downloadProgress = 1;
            
            return;
        }
    }
    
    @weakify(self);
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        @strongify(self);
        [self reloadDownload];
    });
    
    if (!alert) {
        
        return;
    }
    
    if (self.lineModel.inroom) {
        
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:self.lineModel.unionid];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            @strongify(self);
            [IGAlertView alertWithTitle:MYLocalizedString(@"PUBLIC_ALERT", nil) message:MYLocalizedString(@"SITEPLAY_AUTO_DOWNLOAD", nil) cancelButtonTitle:nil commitBtn:MYLocalizedString(@"PUBLIC_OK", nil) commit:nil cancel:nil];
            
            [self downloadStart];
        });
        
        return;
    }
    
    [IGAlertView alertWithTitle:MYLocalizedString(@"PUBLIC_ALERT", nil) message:MYLocalizedString(@"PUBLIC_DOWNLOAD_ALERT_CONTENT", nil) cancelButtonTitle:MYLocalizedString(@"PUBLIC_CANCEL", nil) commitBtn:MYLocalizedString(@"PUBLIC_NOWIFI_DOWNLOAD_ALERT_COMMIT", nil) commit:^{
        @strongify(self);
        [self downloadStart];
    } cancel:nil];
}

- (void)loadDataSource {
    
    if (!self.lineid) {
        return;
    }
    [ActivityIndicatorView showHUDAddedTo:self.view backgroundColor:kBGColor];
    
    @weakify(self);
    [NetAPIManager getLineDetailWithLinID:self.lineid block:^(LineModel *model, NSError *error) {
        @strongify(self);
        
        [ActivityIndicatorView hideHUDAddedTo:self.view];
        self.lineModel = model;
        [self loadDataSourceWithAlert:self.alert];
    }];
}

- (void)reloadDownload {
    
    @weakify(self);
    
    [[DownloadManager sharedManager] downloadStatusForModel:self.lineModel block:^(MCDownloadState state, NSInteger completeCount, NSString *unionid) {
        
        @strongify(self);
        if (![self.lineModel.unionid isEqualToString:unionid]) {
            return ;
        }
        
        if (state == MCDownloadStateNone || state == MCDownloadStateSuspened) {
            self.isDownload = NO;
            
            return ;
        }
        
        if (self.isSuspend) {
            
            return;
        }
        
        self.isDownload = YES;
        
        CGFloat progress = completeCount * 1.0 / self.lineModel.records.count;
        
        self.playBar.downloadState = state;
        self.playBar.downloadProgress = progress;
    }];
}


- (void)setupData {
    
    //self.title= self.lineModel.linename;
    if (self.lineModel.records.count > 0) {
        
        self.dataSource = [NSMutableArray arrayWithArray:self.lineModel.records];
        
        self.playBar.lineModel = self.lineModel;
        self.playBar.pointsArray = self.dataSource;
    }
    
    self.menuTagsArray = [NSMutableArray arrayWithArray:@[@(MenuTypeQuestion),@(MenuTypeComment),@(MenuTypeMap),@(MenuTypeCamera),@(MenuTypeNode)]];
    
    [self initSelectedCell];
    [self setupMenuView];
    [self.collectionView reloadData];
    
}

- (void)initSelectedCell {
    
    ScenicPoint *model;
    NSIndexPath * indexPath;
    if ( self.dataSource.count > 0 && !self.currentScenicPoint) {
        
        model = self.dataSource[0];
        indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        self.currenIndexPath = indexPath;
        self.currentScenicPoint = model;
        [[IGAvPlayerManager shareManeger] resetPlaySpeed];
        [self.playBar playMusicWithIndex:0 withIsPlay:NO];
        
    } else {
        
        NSInteger index = [self.dataSource indexOfObject:self.currentScenicPoint];
        
        model = self.currentScenicPoint;
        
        indexPath = [NSIndexPath indexPathForRow:index inSection:0];
        self.currenIndexPath = indexPath;
        self.playBar.playPath = model.playpath;
        //        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //
        //            [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        //        });
        
        if (![IGAvPlayerManager shareManeger].isPlay) {
            
            [self.playBar playMusicWithIndex:index withIsPlay:NO];
            self.playBar.progressTrackValue = 1.0f;
        }
        
    }
    
    self.currentIndex = indexPath.row;
    self.cycleScrollView.imageURLStringsGroup = model.pictureArray;
    
    [self maskViewAppear];
}

- (IBAction)goGuiderDetailVC:(UIButton *)sender {
    
    //    [MobClick event:@"7_1_4"];
    //    for (UIViewController *vc in self.navigationController.viewControllers) {
    //
    //        if ([vc isKindOfClass:[GuiderDetailVC class]]) {
    //            [self.rt_navigationController removeViewController:vc];
    //        }
    //
    //        if ([vc isKindOfClass:[BasePlayVC class]] && vc != self) {
    //            [self.rt_navigationController removeViewController:vc];
    //        }
    //    }
    
    //    GuiderDetailVC * detailVC = [[GuiderDetailVC alloc] init];
    //
    //    detailVC.guiderID = self.lineModel.guideid;
    //    [self.navigationController pushViewController:detailVC animated:YES];
    
}


//-(void) configScenicPointNumLableWith:(NSInteger )count {
//
//    NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld个讲解点",self.lineModel.records.count]];
//
//    // 设置字体和设置字体的范围
//    [string addAttribute:NSFontAttributeName
//                   value:Font(18.0f)
//                    range:NSMakeRange(0, string.length - 4)];
//    // 添加文字颜色
//    [string addAttribute:NSForegroundColorAttributeName
//                    value:kThemeColor
//                    range:NSMakeRange(0, string.length - 4)];
//
//    self.scenicPointNumLabel.attributedText = string;
//}

- (void)setupCollectionView {
    
    self.barBGAlpha = 0.f;
    
    CGRect frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 98);
    self.bgViewBottomSpace.constant = 98;
    if (ISiPhoneX) {
        frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 132);
        self.bgViewBottomSpace.constant = 132;
    }
    // 网络加载 --- 创建带标题的图片轮播器
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:frame delegate:nil placeholderImage:[UIImage imageNamed:@"placeholder_squ"]];
    [self.BgView insertSubview:self.cycleScrollView belowSubview:self.menuView];
    self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    self.cycleScrollView.delegate = self;
    self.cycleScrollView.currentPageDotColor = kThemeColor; // 自定义分页控件小圆标颜色
    self.cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"SearchScenicPointCCell" bundle:nil] forCellWithReuseIdentifier:@"SearchScenicPointCCell"];
    
    UICollectionViewFlowLayout *flayout = [[UICollectionViewFlowLayout alloc] init];
    
    CGFloat width = (kScreenWidth - 48)/3;
    flayout.itemSize = CGSizeMake(width, width + 25);
    flayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flayout.minimumLineSpacing = 12;
    flayout.minimumInteritemSpacing = 8;
    [self.collectionView setCollectionViewLayout:flayout animated:YES];
    
    self.collectionView.hidden = YES;
}


- (void)createPlayBar {
    
    if (!self.playBar) {
        
        self.playBar = [PlayBar shareManeger];
        self.playBar.delegate = self;
        self.playBar.type = 2;
        [self.view addSubview:self.playBar];
        [self.playBar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.BgView.mas_bottom).offset(8.0);
            make.leading.equalTo(self.view.mas_leading);
            make.trailing.equalTo(self.view.mas_trailing);
            make.width.mas_equalTo(kScreenWidth);
            if (ISiPhoneX) {
                make.height.mas_equalTo(124);
            }else {
                make.height.mas_equalTo(90);
            }
            
        }];
    }
    
    self.playBar.downloadState = MCDownloadStateNone;
}
//- (void)setupNavBar {
//
//    [[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:0];
//
//    UIBarButtonItem *  backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnClicked:)];
//    self.navigationItem.leftBarButtonItem = backItem;
//
//    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"more"] style:UIBarButtonItemStylePlain target:self action:@selector(showMoreMennu)];
//
//    self.navigationItem.rightBarButtonItem = item;
//}

- (void)downloadStart {
    
    
    if (![IGUtil hasLoginOrPresentLogin]) {
        return;
    }
    
    self.isDownload = YES;
    self.isSuspend = NO;
    
    [[DownloadManager sharedManager] addDownloadWithLineModel:self.lineModel];
}

- (void)downloadSuspend {
    
    self.isDownload = NO;
    self.isSuspend = YES;
    
    [[DownloadManager sharedManager] pauseWithLineModel:self.lineModel];
}

- (void)loginSuccessCallback {
    [self loadDataSourceWithAlert:NO];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - playBarDelegate

- (void)changePointTo:(NSInteger)index{
    
    [self changeScenicPointWithIndex:index];
}

#pragma mark-UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    if (!self.isAll) {
        return self.resultArray.count;
    }
    return self.dataSource.count;
}
- ( UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    SearchScenicPointCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SearchScenicPointCCell" forIndexPath:indexPath];
    
    //    if (self.isDownload) {
    //        cell.showProgress = YES;
    //    } else {
    //        cell.showProgress = NO;
    //    }
    ScenicPoint * scenicPoint;
    if (!self.isAll) {
        scenicPoint = self.resultArray[indexPath.row];
    }else {
        scenicPoint = self.dataSource[indexPath.row];
    }
    
    //    [cell configDataWith:scenicPoint];
    [cell configData:scenicPoint];
    
    //    if (indexPath.row == 0  && !self.lineModel.bought) {
    //        cell.playBtn.hidden = NO;
    //    }
        cell.select = NO;
    
        if (self.currenIndexPath.row == indexPath.row  && self.isAll) {
            cell.select = YES;
        }
    
    return cell;
}

- (void)selectCellWithIndex:(NSInteger)index Immediately:(BOOL)isImmediately {
    
    [self changeScenicPointWithIndex:index];
    [self.playBar playMusicWithIndex:index withIsPlay:isImmediately];
}

- (void)changeScenicPointWithIndex:(NSInteger)index {
    
    ScenicPoint * scenicPoint = self.dataSource[index];
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
    
    if (self.currenIndexPath) {
                SearchScenicPointCCell * cell = (SearchScenicPointCCell *)[self.collectionView cellForItemAtIndexPath:self.currenIndexPath];
         cell.select = NO;
    }
        SearchScenicPointCCell * currenCell = (SearchScenicPointCCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
     currenCell.select = YES;
    if (scenicPoint.spotpictures && !self.changeMapBtn.selected) {
        
        
        self.cycleScrollView.imageURLStringsGroup = scenicPoint.pictureArray;
        
    }else  if(scenicPoint.map.length > 0){
        
        [self.cycleScrollView selectToIndex:[self.lineModel.mapPicArray indexOfObject:scenicPoint.map]];
    }
    
    
    //    IGLog(@"%@",model.playpath);
    //    [self.playBar playMusicWithPlayPath:model withIsPlay:isImmediately];
    
    // [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
    [self.collectionView reloadData];
    self.currenIndexPath = indexPath;
    self.currentIndex = indexPath.row;
    self.currentScenicPoint = scenicPoint;
    
    if (self.maskView.hidden) {
        
        self.title = self.currentScenicPoint.spotname;
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    ScenicPoint * scenicPoint;
    if (self.isAll) {
        
        if (self.currenIndexPath == indexPath) {
            return;
        }
        scenicPoint = self.dataSource[indexPath.row];
        if (scenicPoint.playpath.length > 0) {
            
            [self selectCellWithIndex:indexPath.row Immediately:YES];
        }
    }else {
        scenicPoint = self.resultArray[indexPath.row];
        if (scenicPoint.playpath.length > 0) {
            
            [self selectSenicPoint:scenicPoint];
        }
    }
    
    [self maskViewDisappearIsAnimation:YES];
}

- (void)paySuccessCallback {
    [self loadDataSourceWithAlert:YES];
}
#pragma mark-UICollectionViewDelegateFlowLayout
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                        layout:(UICollectionViewLayout *)collectionViewLayout
        insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(8, 16, 8, 16);//分别为上、左、下、右
}


#pragma mark-SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
    if (self.changeMapBtn.selected) {
        if (self.lineModel.mapPicArray.count > 0) {
            
            SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
            
            browser.sourceImagesContainerView = cycleScrollView;
            browser.currentImageIndex = index;
            browser.imageCount = self.lineModel.mapPicArray.count;
            
            browser.delegate = self;
            [browser show];
        }
    }else {
        [self maskViewAppear];
        [self showSearchOrAllPointWith:self.isSearchOrAllPoint];
    }
    
    
    
}

- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
    
    NSString *picstr = self.lineModel.mapPicArray[index];
    
    return [UIImageView imageFromDiskCacheForKey:picstr];
}
- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
    
    NSString *picstr = self.lineModel.mapPicArray[index];
    
    return [NSURL URLWithString:picstr];
}


#pragma  mark   --UIImagePickerControllerDelegate

//- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
//
//    [picker dismissViewControllerAnimated:YES completion:nil];
//    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
//    if ([type isEqualToString:@"public.image"]) {
//
//
//        UIImage* originalImg = [info objectForKey:UIImagePickerControllerOriginalImage];
//
//
//    }
//}
//- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
//
//    [picker dismissViewControllerAnimated:YES completion:nil];
//}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
